home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / program / vsa256.zip / VSA_DEMO.C < prev    next >
C/C++ Source or Header  |  1996-06-01  |  28KB  |  789 lines

  1. /*..........................................................................*/
  2. /*                               VSA_DEMO.C              5-29-96            */
  3. /*                                                                          */
  4. /*  This is the "C" source code for the VSA_DEMO.EXE program.  This program */
  5. /*  demonstrates the usage of the VSA256 Graphics Library, Version 4.0.     */
  6. /*  functions.                                                              */
  7. /*                                                                          */
  8. /*            Note: Set STACK SIZE to approx 10000 bytes.                   */
  9. /*            Note: For BORLAND compilers, use -Fs flag (SS = DS)!          */
  10. /*                                                                          */
  11. /*         Copyright Spyro Gumas, 1992 - 1996.  All Rights Reserved.        */
  12. /*..........................................................................*/
  13.  
  14. #include<dos.h>
  15. #include<stdio.h>
  16. #include<stdlib.h>
  17. #include<math.h>
  18. #include<limits.h>
  19. #include<bios.h>
  20. #include<conio.h>
  21. #include<time.h>
  22.  
  23. #include <vsa.h>            /* Required to support VSA256 Graphics Library  */
  24. #include <vsa_font.h>       /* Required to support VSA256 Graphics Library  */
  25. #include <tiff.h>           /* Required to support TIFF256 Graphics Library */
  26.  
  27. #ifndef _MSC_VER
  28. /*.....                  This is for Borland C Only !                  .....*/
  29. extern unsigned _stklen = 10000;
  30. #endif
  31.  
  32. void cube(int,int,int);
  33. void cubes(int,int,int);
  34. void rainbow_lut(void);
  35. void shaded_lut(void);
  36. void color_bar(int,int);
  37. void banner(int,int);
  38. void image(int,int);
  39. void obj_3d(int,int);
  40. void cube_3d(int,int);
  41. int  any_key(void);
  42. void delay(unsigned);
  43. void color_effect(void);
  44. void vsa_get_input(char *);
  45. void vsa_setup(void);
  46. void blueberry(void);
  47. void flipper(void);
  48. void pgram(int,int,int,int,int,int,int,int);
  49.  
  50. float SIN_LUT[1024];
  51.  
  52. void main()
  53. {
  54.     int i,k,l,ty,tx,c1,c2,vmode;
  55.     unsigned xx,yy,a,b,c,d,m,n,oldm,oldn,image_size;
  56.     char your_name[80];
  57.     unsigned char *pict1;
  58.     float x_scale,y_scale;
  59. /*..........................................................................*/
  60. /* If demo locks up during color cycling, or color mods crash for whatever  */
  61. /* reason, set the global parameter VSA_ATI_COLOR = 1.                      */
  62. /*..........................................................................*/
  63. //    VSA_ATI_COLOR = 1;
  64. /*..........................................................................*/
  65. /*                      Initialize sin look up table.                       */
  66. /*  Index 'i' goes from 0 to 1023 and is equivalent to 0 to 360 degrees.    */
  67. /*..........................................................................*/
  68.     for(i=0;i<1024;i++)
  69.         SIN_LUT[i] = sin(i*6.28/1024.0);
  70.  
  71.     vsa_setup();
  72.     vsa_get_svga_mode(&vmode);
  73.     rainbow_lut();
  74. /*..........................................................................*/
  75. /*                          Draw a BlueBerry Name.                          */
  76. /*..........................................................................*/
  77.     blueberry();
  78. /*..........................................................................*/
  79. /*             Do a quicky Page Flipping Demo in --- 640x480 mode.          */
  80. /*..........................................................................*/
  81.     flipper();
  82. /*..........................................................................*/
  83. /*        Now switch back to user specified vmode and do rest of demo.      */
  84. /*..........................................................................*/
  85.     vsa_init(vmode);
  86.     rainbow_lut();
  87.     xx = XResolution;
  88.     yy = YResolution;
  89.     x_scale = XResolution/640.0;
  90.     y_scale = YResolution/480.0;
  91.     vsa_set_text_scale(x_scale,y_scale);
  92.     vsa_set_color(0);
  93.     vsa_move_to(0,0);
  94.     vsa_rect_fill(xx-1,yy-1);
  95. /*..........................................................................*/
  96. /*                          Draw a frame                                    */
  97. /*..........................................................................*/
  98.     vsa_set_color(1);
  99.     vsa_move_to(0,0);
  100.     vsa_rect(xx-1,yy-1);
  101.     c1 = 30;
  102.     c2 = 20;
  103.     vsa_shaded_triangle(0,0,c1,10,10,c2,10,yy-11,c2);
  104.     vsa_shaded_triangle(0,0,c1,0,yy-1,c1,10,yy-11,c2);
  105.     vsa_shaded_triangle(0,0,c1,xx-1,0,c1,xx-11,10,c2);
  106.     vsa_shaded_triangle(0,0,c1,10,10,c2,xx-11,10,c2);
  107.     vsa_shaded_triangle(0,yy-1,c1,10,yy-11,c2,xx-11,yy-11,c2);
  108.     vsa_shaded_triangle(0,yy-1,c1,xx-1,yy-1,c1,xx-11,yy-11,c2);
  109.     vsa_shaded_triangle(xx-1,0,c1,xx-1,yy-1,c1,xx-11,10,c2);
  110.     vsa_shaded_triangle(xx-1,yy-1,c1,xx-11,yy-11,c2,xx-11,10,c2);
  111. /*..........................................................................*/
  112. /*             Draw color look up table at bottom of screen.                */
  113. /*..........................................................................*/
  114.     a = .125*xx;
  115.     b = .83*yy;
  116.     color_bar(a,b);
  117. /*..........................................................................*/
  118. /*            Draw "random" cubes enclosed by rectangle                     */
  119. /*..........................................................................*/
  120.     a = .6*xx;
  121.     b = .4*yy;
  122.     c = .88*xx;
  123.     d = .72*yy;
  124.     tx = (a+(c-a)/2) - 12*XCharSize;
  125.     ty = d + 0.01*yy;
  126.     vsa_write_string(tx,ty,250,"Lines using `vsa_line_to'");
  127.     vsa_write_string(tx,ty+YCharSize,64,"Clipping: `vsa_set_viewport'");
  128.     vsa_move_to(a,b);
  129.     vsa_set_color(180);
  130.     vsa_rect(c,d);
  131.     vsa_move_to(a+1,b+1);
  132.     vsa_set_color(20);
  133.     vsa_rect_fill(c-1,d-1);
  134.     vsa_set_viewport(a+1,b+1,c-1,d-1);
  135.     srand(1);
  136.     cubes(a,b,1);
  137. /*..........................................................................*/
  138. /*                          Draw a banner                                   */
  139. /*..........................................................................*/
  140.     vsa_set_viewport(0,0,xx,yy);
  141.     a = .55*xx;
  142.     b = .06*yy;
  143.     banner(a,b);
  144. /*..........................................................................*/
  145. /*                    Draw 2D sine-cosine image                             */
  146. /*..........................................................................*/
  147.     a = .08*xx;
  148.     b = .15*yy;
  149.     image(a,b);
  150. /*..........................................................................*/
  151. /*                    Draw a 3-D shaded object                              */
  152. /*..........................................................................*/
  153.     a = .08*xx;
  154.     b = .5*yy;
  155.     obj_3d(a,b);
  156. /*..........................................................................*/
  157. /*                    Draw a 3-D shaded Cube                                */
  158. /*..........................................................................*/
  159.     a = .5*xx;
  160.     b = .35*yy;
  161.     cube_3d(a,b);
  162. /*..........................................................................*/
  163. /*                        Using Text Cursor Mode 1.                         */
  164. /*..........................................................................*/
  165.     ty = .05*yy;
  166.     tx = .05*xx;
  167.     vsa_set_text_cursor_mode(1);
  168.     vsa_write_string(tx,ty,250,"Please Enter Your Name: ");
  169.     vsa_get_input(your_name);
  170.     vsa_set_text_cursor(tx,ty+YCharSize);
  171.     vsa_set_text_color(200);
  172.     vsa_write_string_alt("Hello ");
  173.     vsa_write_string_alt(your_name);
  174.     vsa_write_string_alt(", Hit any key to bail.");
  175. /*..........................................................................*/
  176. /* NOTE: TIFF256 requires Large MEM Model if you uncomment following lines! */
  177. /*..........................................................................*/
  178. /*.....
  179.     printf("Input Full file name for TIFF file to be saved: ");
  180.     scanf("%s",filename);
  181.     tf_save_file(0,YResolution-1,XResolution-1,0,filename);
  182. .....*/
  183. /*..........................................................................*/
  184. /*    Now do moving clipped cubes effect until someone presses a key.       */
  185. /*..........................................................................*/
  186.     k = 0;
  187.     l = 256;
  188.     a = .6*xx;
  189.     b = .4*yy;
  190.     c = .88*xx;
  191.     d = .72*yy;
  192.     oldm = a;
  193.     oldn = b;
  194.     vsa_set_viewport(a+1,b+1,c-1,d-1);
  195.     while(!any_key())
  196.         {
  197.             m = a + xx*0